proc computeSMA {data_table} {
	set xy_value {}
	set x {}
 
	for {set i 0} {$i<[llength $data_table]} {incr i} {
		set row [lindex $data_table $i]
		lappend x [lindex $row 5]
	}	
 
	set n 7
	set sum 0
	for {set i 0} {$i<[llength $x]} {incr i} {
		set last 0
		if {$i >= $n} {
			set last [lindex $x [expr $i-$n]]
		}
		set sum [expr {$sum + [lindex $x $i]}]
		set sum [expr {$sum - $last}]
 
		set avg [expr {$sum / $n}]
		if {$i >= $n} {
			lappend xy_value [list [expr {$i+1}] $avg]
		} else {
			lappend xy_value [list [expr {$i+1}] [lindex $x $i]]
		}
		#puts $avg
	}
 
	return $xy_value
}
 
proc computeEMA {data_table} {
	set xy_value {}
	set x {}
	set close {}
 
	for {set i 0} {$i<[llength $data_table]} {incr i} {
		set row [lindex $data_table $i]
		lappend x [lindex $row 2]
		lappend close [lindex $row 5]
	}	
 
	set n 7
	set sum 0
 
	#compute first ema
	for {set i 0} {$i<$n} {incr i} {
		set sum [expr {$sum + [lindex $x $i]}]
		lappend xy_value [list [expr {$i+1}] [lindex $x $i]]
	}
 
	set ema [expr {$sum / $n}]
 
	#next ema
	set multiplier [expr {2.0 / [expr {$n + 1}]}]
	for {set i $n} {$i<[llength $x]} {incr i} {
		set close_i [lindex $close $i]
		set temp [expr {$close_i - $ema}]
		set temp [expr {$temp * $multiplier}]
		set ema [expr {$temp + $ema}]
		lappend xy_value [list [expr {$i+1}] $ema]
	}
 
	return $xy_value
}
 
 
proc computeZigZag {data_table} {
	set xy_value {}
	set x {}
 
	for {set i 0} {$i<[llength $data_table]} {incr i} {
		set row [lindex $data_table $i]
		lappend x [lindex $row 5]
	}	
 
	set threshold 0.01
	set last [lindex $x 0]
	lappend xy_value [list 1 $last]
	for {set i 1} {$i<[llength $x]} {incr i} {
		set x_i [lindex $x $i]
		if { abs($x_i - $last) > [expr {$last * $threshold}]} {
			lappend xy_value [list [expr {$i+1}] $x_i]
			set last $x_i
		}
	}
 
	return $xy_value
}